﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel.Syndication;
using System.Xml.Linq;
using MSAcademic.v2.Infrastructure.SubSection;
using MSAcademic.v2.Infrastructure.User;

namespace MSAcademic.v2.Infrastructure.Article.Impl
{
    public partial class ArticleRssService:IArticleRssService
    {
        public List<SyndicationItem> BuildLatestArticlesRss(List<IArticle> articles)
        {
            return articles.Select(article => new SyndicationItem() 
            { 
                Title = new TextSyndicationContent(article.Title),
                PublishDate = article.PublishedOn.Value,
                BaseUri = new Uri("http://msacademic.hr/novost/" + article.Id),

                Content = new TextSyndicationContent(article.LongText),
                
            }).ToList();
        }

        public List<SyndicationItem> BuildHightLightedArticlesRss(List<Tuple<ISubSection, List<IArticle>>> articles)
        {
            
            var highlightedArticles = new List<SyndicationItem>();
            foreach (var subsection in articles)
            {
                highlightedArticles.AddRange(subsection.Item2.Select(article => new SyndicationItem(article.Title, article.LongText, new Uri("http://msacademic.hr/novost/" + article.Id))));
            }
            return highlightedArticles;
        }
        public List<SyndicationItem> BuildContentSectionRss(List<IArticle> articles, string contentSectionName)
        {
            return articles.Select(article => new SyndicationItem(article.Title, article.LongText, new Uri("http://msacademic.hr/novost/"+ article.Id))).ToList();
        }

        public List<SyndicationItem> BuildAuthorRss(List<IArticle> articles)
        {
            return articles.Select(a => new SyndicationItem
                                            {
                                                Title = new TextSyndicationContent(a.Title),
                                                PublishDate = a.PublishedOn.Value, 
                                                BaseUri = new Uri("http://msacademic.hr/novost/" + a.Id), 
                                                Content = new TextSyndicationContent(a.LongText)
                                            }).ToList();
        }

        public SyndicationItem BuildArticleRss(IArticle article)
        {
            var root = new SyndicationItem(article.Title,article.LongText,new Uri("http://msacademic.hr/novost/" + article.Id));
            
            return root;
        }
        
    }
     public partial class ArticleRssService
     {
         public List<SyndicationItem> HomeRssMerge(List<SyndicationItem> highlighted, List<SyndicationItem> latest)
         {
             var rss = highlighted.ToList();
             rss.AddRange(latest);
             
             return rss;
         }

     }
}
